package com.sample.utils;

import java.io.IOException;
import java.net.ConnectException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.HttpHostConnectException;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;

public class WebQuest {
	public static String requestOne(String urlStr,String uname, String pwd) {

		String msg = "";
		
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		
		
		params.add(new BasicNameValuePair("id", uname));
		params.add(new BasicNameValuePair("pwd", pwd));

		HttpPost request = new HttpPost(urlStr);
		
		
		try {
			request.setEntity(new UrlEncodedFormEntity(params, HTTP.ISO_8859_1));
			
			DefaultHttpClient httpClient = new DefaultHttpClient();
			
			HttpResponse response = httpClient.execute(request);
			
			if (response.getStatusLine().getStatusCode() == 200) {
				msg = EntityUtils.toString(response.getEntity());
			}
		}catch (HttpHostConnectException ex) {
			msg = "neterror";
		}	catch (ConnectException ex) {
			msg = "neterror";	

		}catch (ClientProtocolException e) {
			msg = "protocloerror";
		} catch (IOException e) {
			msg = "ioerror";
		}  


		return msg;
	}
}
